package com.n4v1.pko.client.model.actor;

import java.util.ArrayList;

import org.newdawn.slick.Animation;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.SpriteSheet;

public class Character {
	private String login;
	private float x;
	private float y;
	private boolean isMoving;
	private int direction;
	private ArrayList<Animation> animations;
	
	public Character(String login, float x, float y) throws SlickException {
		super();
		this.login = login;
		this.x = x;
		this.y = y;
		this.animations = new ArrayList<Animation>();
		SpriteSheet sheet = new SpriteSheet("data/sprites/characters/guard.png",32,32);
		for(int i = 0; i < 4; i++) {
			animations.add(new Animation());
			animations.get(i).setAutoUpdate(false);
			for (int frame=0;frame<3;frame++) {
				animations.get(i).addFrame(sheet.getSprite(frame,1), 150);
			}
		}
	}
	
	public void draw(float xpos, float ypos) {
		int cx = (int) (xpos * 32);
		int cy = (int) (ypos * 32);
		animations.get(direction).draw(cx-16,cy-16);
	}
	
	public boolean isMoving() {
		return isMoving;
	}
	
	public void goDown() {
		this.direction = 0;
		this.startMoving();
	}
	
	public void goLeft() {
		this.direction = 1;
		this.startMoving();
	}
	
	public void goRight() {
		this.direction = 2;
		this.startMoving();
	}
	
	public void goUp() {
		this.direction = 3;
		this.startMoving();
	}
	
	public void startMoving() {
		this.isMoving = true;
	}
	
	public void stopMoving() {
		this.isMoving = false;
	}
	
	public int getDirection() {
		return this.direction;
	}
}
